package com.wu.web;

import com.alibaba.fastjson.JSON;
import com.wu.bean.CategoryTable;
import com.wu.service.CategoryTableService;
import com.wu.service.impl.CategoryTableServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/SelectCategoryTableAll")
public class SelectCategoryTableAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        CategoryTableService categoryTableService=new CategoryTableServiceImpl();
        List<CategoryTable> categoryTables = categoryTableService.queryCategoryTableAll();
        String json= JSON.toJSON(categoryTables).toString();
        System.out.println(json);
        resp.getWriter().print(json);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
